package com.hwadeefsc.springboot.service.impl;

import com.hwadeefsc.springboot.dao.RewardsPunishmentsDao;
import com.hwadeefsc.springboot.entity.RewardsPunishments;
import com.hwadeefsc.springboot.service.RewardsPunishmentsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (RewardsPunishments)表服务实现类
 *
 * @author makejava
 * @since 2024-07-09 21:43:27
 */
@Service("rewardsPunishmentsService")
public class RewardsPunishmentsServiceImpl implements RewardsPunishmentsService {
    @Resource
    private RewardsPunishmentsDao rewardsPunishmentsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param rpId 主键
     * @return 实例对象
     */
    @Override
    public RewardsPunishments queryById(Integer rpId) {
        return this.rewardsPunishmentsDao.queryById(rpId);
    }

    /**
     * 分页查询
     *
     * @param rewardsPunishments 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<RewardsPunishments> queryByPage(RewardsPunishments rewardsPunishments, PageRequest pageRequest) {
        long total = this.rewardsPunishmentsDao.count(rewardsPunishments);
        return new PageImpl<>(this.rewardsPunishmentsDao.queryAllByLimit(rewardsPunishments, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param rewardsPunishments 实例对象
     * @return 实例对象
     */
    @Override
    public RewardsPunishments insert(RewardsPunishments rewardsPunishments) {
        this.rewardsPunishmentsDao.insert(rewardsPunishments);
        return rewardsPunishments;
    }

    /**
     * 修改数据
     *
     * @param rewardsPunishments 实例对象
     * @return 实例对象
     */
    @Override
    public RewardsPunishments update(RewardsPunishments rewardsPunishments) {
        this.rewardsPunishmentsDao.update(rewardsPunishments);
        return this.queryById(rewardsPunishments.getRpId());
    }

    /**
     * 通过主键删除数据
     *
     * @param rpId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer rpId) {
        return this.rewardsPunishmentsDao.deleteById(rpId) > 0;
    }

    @Override
    //从奖惩中得到学生
    public List<Map<String, Object>> queryBytype(String type) {

        return this.rewardsPunishmentsDao.gettypeofRP(type);
    }
//从学生id中得到奖惩信息
    @Override
    public List<Map<String, Object>> queryByStdId(Integer StudentId) {
        return this.rewardsPunishmentsDao.getstudentRP(StudentId);
    }
}
